package com.huluobo.a2303mdmdemo.video

import androidx.room.util.ViewInfo
import com.huluobo.lib_base.BaseViewModel
import com.huluobo.lib_base.Res
import com.huluobo.lib_base.StateType
import com.huluobo.lib_base.UIIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
 *  Created by LC on 2025/8/29.
 */
@HiltViewModel
class VideoViewModel @Inject constructor(private val videoRepo: VideoRepo) : BaseViewModel<VideoIntent>() {
    override fun handleIntent(it: UIIntent) {
        when (it) {
            is VideoIntent.GetAllVideos -> {
                httpRequest(videoRepo.getAllVideos(it.currentPage, it.pageSize) as Flow<Res<Any>>)
            }

            is VideoIntent.LikeVideo -> {
                httpRequest(videoRepo.likeVideo(it.videoId) as Flow<Res<Any>>, StateType.LIKE)
            }

            is VideoIntent.NoLikeVideo -> {
                httpRequest(videoRepo.noLikeVideo(it.videoId) as Flow<Res<Any>>, StateType.NO_LIKE)
            }

            is VideoIntent.GetAllComment -> {
                httpRequest(videoRepo.getAllComment(it.videoId) as Flow<Res<Any>>, StateType.GET_COMMENT)
            }

            is VideoIntent.SendComment -> {
                httpRequest(videoRepo.sendComment(it.map) as Flow<Res<Any>>, StateType.SEND_COMMENT)
            }

            is VideoIntent.CollectVideo -> {
                roomRequest(videoRepo.collectVideo(it.videoEntityItem), StateType.COLLECT)
            }

            is VideoIntent.GetCollectVideo -> {
                roomRequest(videoRepo.getCollectVideos())
            }

            is VideoIntent.DeleteCollect -> {
                roomRequest(videoRepo.deleteCollectVideo(it.videoEntityItem), StateType.DELETE)
            }

            is VideoIntent.FollowAuth -> {
                httpRequest(videoRepo.followAuth(it.map) as Flow<Res<Any>>, StateType.FOLLOW_AUTH)
            }
        }
    }
}